home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IO Examples / IO Utilities / Random.icl < prev   
Encoding:
Modula Implementation  |  1996-12-18  |  582 b   |  25 lines  |  [TEXT/3PRM]

  1. implementation module Random
  2.  
  3.  
  4. import    StdInt, StdClass
  5. from    deltaTimer    import    GetCurrentTime, CurrentTime, IOState
  6.  
  7.  
  8. ::    RandomSeed    :== Int
  9.  
  10.  
  11. NullRandomSeed :: RandomSeed
  12. NullRandomSeed = 0
  13.  
  14. GetNewRandomSeed :: !(IOState *s) -> (!RandomSeed, !IOState *s)
  15. GetNewRandomSeed io
  16. #    ((hours,minutes,seconds), io)    = GetCurrentTime io
  17. =    (1+(hours+minutes+seconds) bitand 65535, io)
  18.  
  19. Random :: !RandomSeed -> (!Int,!RandomSeed)
  20. Random seed            = (newSeed,newSeed)
  21. where
  22.     newSeed            = if (nextSeed>=0) nextSeed (nextSeed+65537)
  23.     nextSeed        = (seed75 bitand 65535)-(seed75>>16)
  24.     seed75            = seed*75
  25.